/**
 * EasyBeans
 * Copyright (C) 2008 Bull S.A.S.
 * Contact: easybeans@ow2.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id: MessageDispatcherWrapper.java 4389 2008-12-15 13:48:57Z alitokmen $
 * --------------------------------------------------------------------------
 */
package br.unifor.util.cluster.jgcs;

import java.io.IOException;
import java.net.SocketAddress;
import java.util.Vector;

import net.sf.jgcs.ControlSession;
import net.sf.jgcs.DataSession;
import net.sf.jgcs.JGCSException;
import net.sf.jgcs.Message;
import net.sf.jgcs.Service;
import net.sf.jgcs.UnsupportedServiceException;
import net.sf.jgcs.membership.MembershipListener;
import net.sf.jgcs.membership.MembershipSession;
import br.unifor.g2cl.IMarshalDataSession;
import br.unifor.g2cl.SuspectedException;
import br.unifor.g2cl.TimeoutException;
import br.unifor.g2cl.hl.IMessageDispatcher;
import br.unifor.g2cl.hl.MessageDispatcher;
import br.unifor.g2cl.hl.MessageDispatcherListener;
import br.unifor.g2cl.hl.RspList;

/**
 * Wrap an instance of {@link MessageDispatcher}.
 * @author Loris Bouzonnet
 */
public class MessageDispatcherWrapper implements IMessageDispatcher {

    private final MessageDispatcher messageDispatcher;

    public MessageDispatcherWrapper(final MessageDispatcher messageDispatcher) {
        super();
        this.messageDispatcher = messageDispatcher;
    }

	public MessageDispatcherWrapper(IMarshalDataSession marshalDataSession,
			MembershipSession membershipSession, 
			Service service) throws JGCSException {
		messageDispatcher = new MessageDispatcher(marshalDataSession,membershipSession,service);
	}
    
	public RspList castMessage(Vector<SocketAddress> dests, Message msg,
			int mode, long timeout) throws UnsupportedServiceException,
			IOException {
		return messageDispatcher.castMessage(dests, msg, mode, timeout);
	}

	public ControlSession getControlSession() {
		// TODO Auto-generated method stub
		return messageDispatcher.getControlSession();
	}

	public DataSession getDataSesson() {
		return messageDispatcher.getDataSesson();
	}

	public Service getService() {
		return messageDispatcher.getService();
	}

	public boolean isLocal() {
		return messageDispatcher.isLocal();
	}

	public Object sendMessage(Message msg, SocketAddress dest, int mode,
			long timeout) throws TimeoutException, SuspectedException,
			UnsupportedServiceException, IOException {
		return messageDispatcher.sendMessage(msg, dest, mode, timeout);
	}

	public void setLocal(boolean local) {
		messageDispatcher.setLocal(local);
		
	}

	public void setMembershipListener(MembershipListener membershipListener) {
		messageDispatcher.setMembershipListener(membershipListener);
		
	}

	public void setMessageDispatcherListener(
			MessageDispatcherListener messageDispatcherListener) {
		messageDispatcher.setMessageDispatcherListener(messageDispatcherListener);
		
	}

	public void stop() {
		messageDispatcher.stop();
		
	}
}
